const Biz = require('../biz/index');
const fw = require('../core/framework');

module.exports = {
    init(router,urlencodedParser,checkLogin,loginUsers){
        router.post('/alarmContactGroupDevice/create', urlencodedParser, function(req, res) {
            fw.checkLogin(req,res,function(){
                let param = fw.utils.parseBody(req);
                let cData = {
                    alarm_contact_group_id:param.alarm_contact_group_id,
                    device_id:param.device_id,
                    merchant_id:fw.parseMerchantId(req)
                };
                Biz.AlarmContactGroupDevice.create(cData,(data)=>{
                    res.send(data);
                },(data)=>{
                    res.send(data);
                });
            });
        });
        router.post('/alarmContactGroupDevice/update', urlencodedParser, function(req, res) {
            fw.checkLogin(req,res,function(){
                let param = fw.utils.parseBody(req);
                if(fw.isExit(param.id)){
                    Biz.AlarmContactGroupDevice.update(param,(data)=>{
                        res.send(data);
                    },(data)=>{
                        res.send(data);
                    });
                }else{
                    res.send(exception.paramEx('id'));
                }
            });
        });
        router.post('/alarmContactGroupDevice/delete', urlencodedParser, function(req, res) {
            fw.checkLogin(req,res,function(){
                console.log('执行删除账户业务');
                let param = fw.utils.parseBody(req);
                if(fw.isExit(param.id)){
                    Biz.AlarmContactGroupDevice.delete(param,(data)=>{
                        res.send(data);
                    },(data)=>{
                        res.send(data);
                    });
                }else{
                    res.send(exception.paramEx('id'));
                }
            });
        });
        router.post('/alarmContactGroupDevice/search', urlencodedParser, function(req, res) {
            fw.checkLogin(req,res,function(){
                let param = fw.utils.parseBody(req);
                param.merchant_id = fw.parseMerchantId(req);
                Biz.AlarmContactGroupDevice.search(param,(data)=>{
                    res.send(data);
                },(data)=>{
                    res.send(data);
                });
            });
        });
    }
};
